Skip to content

[UPDATED]rat_in_maze.py #9087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from

Conversation

Muhammadummerr
Copy link
Contributor

@Muhammadummerr Muhammadummerr commented Sep 24, 2023

Describe your change:

FIXES #9066
I have made updates to the rat_in_maze.py file to enhance code clarity.
These updates include:
1.Adding more descriptive comments to explain the logic and steps of the maze-solving algorithm.
2.Introducing variables that allow for easy customization of the source and destination cells within the maze.
3.Refactor path representation in solution:

  • Previously, in solution paths were represented as 1s, but I have updated it to use 0s to align with the standard convention where 0s represent paths and 1s represent walls.
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@Muhammadummerr Muhammadummerr changed the title New branch [UPDATED]#9066 rat_in_maze.py Sep 24, 2023
@rohan472000
Copy link
Contributor

Kindly tick the checkboxes while raising PR, don't delete them.

@Muhammadummerr
Copy link
Contributor Author

Kindly tick the checkboxes while raising PR, don't delete them.

Ok, but now how to tick checkboxes when PR is raised?

@rohan472000
Copy link
Contributor

Replace • [ ] to • [x]

@Muhammadummerr
Copy link
Contributor Author

Sorry, but where?

@rohan472000
Copy link
Contributor

rohan472000 commented Sep 25, 2023

While creating PR, you will get a box to describe the change, below in the box there are multiple checkboxes to tick.

https://github.com/TheAlgorithms/Python/blob/master/.github/pull_request_template.md

@Muhammadummerr
Copy link
Contributor Author

should I delete this PR now, and create another one and tick checkboxes?

@rohan472000
Copy link
Contributor

No...copy from that link which I provided, and paste it in description box above, then tick required checkboxes.

@rohan472000
Copy link
Contributor

Also revise the PR title, don't include 9066, this should be in description box, see contributing guidelines beforehand.

@Muhammadummerr Muhammadummerr changed the title [UPDATED]#9066 rat_in_maze.py [UPDATED]rat_in_maze.py Sep 25, 2023
@Muhammadummerr
Copy link
Contributor Author

Thanks a lot, your guidance meant a lot to me:)

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Sep 26, 2023
Copy link
Contributor Author

@Muhammadummerr Muhammadummerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the correction.

@dlesnoff
Copy link

I am not familiar with the Python repository, but I think that you should reflect the changes in the unittest.
What happens if I change the starting cell and the end cell?
An example in the docstring with this new feature would be welcome too.

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Sep 28, 2023
@rohan472000
Copy link
Contributor

At line 19, a lack of a blank line after >>>: '>>>>>>> origin/new_branch' is given in error but text '>>>>>>> origin/new_branch' doesn't appear to be related to the code or docstring.

I have suggested change, commit that and see if it resolves the issue or not.

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Sep 29, 2023
@rohan472000
Copy link
Contributor

None would be better.

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Sep 29, 2023
@rohan472000
Copy link
Contributor

Use ruff . then ruff . --fix to rectify ruff issues.

@Muhammadummerr
Copy link
Contributor Author

Use ruff . then ruff . --fix to rectify ruff issues.

3 errors found ,then how should I resolve them without using ruff --fix .
On running the file it showing error of whitespaces ====== ,How it can be resolved?

@rohan472000
Copy link
Contributor

run : ruff . --fix

@Muhammadummerr
Copy link
Contributor Author

run : ruff . --fix

still 3 errors found
Desktop\Python\backtracking\rat_in_maze.py:35:89: E501 Line too long (93 > 88 characters)
Desktop\Python\backtracking\rat_in_maze.py:82:89: E501 Line too long (93 > 88 characters)
Desktop\Python\backtracking\rat_in_maze.py:105:89: E501 Line too long (216 > 88 characters)

@Muhammadummerr
Copy link
Contributor Author

run : ruff . --fix

using black . showing All done but ruff . --fix showing 3 erros found

@Muhammadummerr
Copy link
Contributor Author

I understand what the problem is. The output of solve_maze is a 2D array written in the docstring as [[0, 1, 1], [0, 0, 1], [0, 0, 1]], but it exceeds the 88-character word limit. Now, when I format the line, the expected output does not match the obtained output. Can you help me in how to approach this issue now?

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Sep 29, 2023
Copy link
Contributor

@rohan472000 rohan472000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove print statement as it is returning None.

"""
size = len(maze)
# Check if source and destination coordinates are Invalid.
if not (0 <= source_row <= size - 1 and 0 <= source_column <= size - 1):
print("Invalid source coordinates")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print("Invalid source coordinates")

print("Invalid source coordinates")
return None
elif not (0 <= destination_row <= size - 1 and 0 <= destination_column <= size - 1):
print("Invalid destination coordinates")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print("Invalid destination coordinates")

if solved:
print("\n".join(str(row) for row in solutions))
return solutions
else:
print("No solution exists!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print("No solution exists!")

@tianyizheng02
Copy link
Contributor

Thank you for your contribution, but unfortunately we're not accepting new PRs at the moment. We're currently trying to clear our backlog of existing PRs in preparation for Hacktoberfest. If you want to contribute, please wait until after October 1 to do so. See this discussion for more info.

@Muhammadummerr Muhammadummerr deleted the new_branch branch September 30, 2023 16:24
@dlesnoff
Copy link

dlesnoff commented Oct 1, 2023

At line 19, a lack of a blank line after >>>: '>>>>>>> origin/new_branch' is given in error but text '>>>>>>> origin/new_branch' doesn't appear to be related to the code or docstring.

I have suggested change, commit that and see if it resolves the issue or not.

The '>>>>>>>' and '======' stuff comes from the git merge. When there is a conflict (a file being changed in the two original branches), git modify the file and let the two code versions in the same file separated by <<<<<<<, ========== and >>>>>>. See the Git documentation.

@Muhammadummerr Muhammadummerr deleted the new_branch branch

Why did you deleted the branch? It is a temporary closed PR. A link to the new PR would have been welcomed!

@dlesnoff dlesnoff mentioned this pull request Oct 3, 2023
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Backtracking/Rat Maze
4 participants